<template>
  <div>
    <!-- 顶部导航 -->
    <van-nav-bar :title="comment.reply_count ? comment.reply_count + '条回复' : '暂无回复'">
      <template #left>
        <van-icon name="cross" @click="$emit('close-popup')" />
      </template>
    </van-nav-bar>

    <div class="scroll-wrap">
      <!-- 当前评论信息 -->
      <CommentItem :comment="comment" />

      <!-- 评论回复 -->
      <van-cell title="全部回复" />
      <ArticleComment type="c" :source="comment.com_id" :list="list" />
    </div>

    <div class="post-warp">
      <van-button @click="isShowReplyPost = true" round>评论</van-button>
    </div>

    <!-- 回复评论弹出层 -->
    <van-popup v-model="isShowReplyPost" position="bottom">
      <ArticlePost @onPostSuccess="onPostSuccess" :target="comment.com_id" :artId="$route.params.articleId" />
    </van-popup>
  </div>
</template>

<script>
import CommentItem from './comment-item.vue'
import ArticleComment from './article-comment.vue'
import ArticlePost from './post-comment.vue'
export default {
  data () {
    return {
      list: [],
      isShowReplyPost: false
    }
  },

  components: {
    CommentItem,
    ArticleComment,
    ArticlePost
  },

  props: {
    comment: {
      type: Object,
      required: true
    }
  },

  created () {
    console.log('回复评论')
  },

  methods: {
    // 监听发布成功的操作
    onPostSuccess (e) {
      this.isShowReplyPost = false
      this.list.unshift(e)
      this.comment.reply_count++
    }
  }
}
</script>

<style scoped lang='less'>
.scroll-wrap {
  position: fixed;
  top: 92px;
  bottom: 102px;
  width: 100%;
  overflow-y: scroll;
}
.post-warp {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  height: 88px;
  display: flex;
  align-items: center;
  justify-content: center;
  background-color: #fff;
  border-top: 1px solid #d8d8d8;
  .van-button {
    width: 640px;
    height: 80px;
  }
}
</style>
